<template>
  <div class="nav-wrap">
    <div class="navs">
      <div
        v-for="(item, index) in navItem"
        :key="index"
        @click="setIndex(index, item)"
        v-bind:class="['nav-item', Index === index ? 'active' : '']"
      >
        {{ item }}
      </div>
    </div>
    <div class="content">
      {{ content }}
    </div>
  </div>
</template>

<script>
export default {
  name: '',
  data() {
    return {
      content: 'HTML',
      navItem: ['HTML', 'CSS', 'JS', 'VUE'],
      Index: 0
    }
  },
  methods: {
    setIndex(index, item) {
      this.Index = index
      this.content = item
    }
  }
}
</script>

<style scoped lang="less">
.nav-wrap {
  width: 500px;
  margin: 0 auto;
  .navs {
    width: 100%;
    height: 50px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    .nav-item {
      width: 100%;
      height: 100%;
      border: 1px solid #000;
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: green;
      cursor: pointer;
      &.active {
        background-color: pink;
      }
    }
  }
}
</style>
